package com.example.bookManagement.Model;

import com.example.bookManagement.enmus.ResultStatus;
import lombok.Data;
import org.springframework.stereotype.Component;

@Data
@Component
public class Result<T> {
    private ResultStatus status;
    private String errorMessage;
    private T data;
    public static <T> Result<T> success(T data) {
        Result result = new Result();
        result.setData(data);
        result.setErrorMessage("");
        result.setStatus(ResultStatus.SUCCESS);
        return result;
    }
    public static  Result fail(String msg) {
        Result result = new Result();
        result.setStatus(ResultStatus.FAIL);
        result.setErrorMessage(msg);
        result.setData("");
        return result;
    }
    public static  Result fail(ResultStatus status,String errorMessage) {
        Result result = new Result();
        result.setStatus(status);
        result.setErrorMessage(errorMessage);
        return result;
    }
    public static Result unlogin() {
        Result result = new Result();
        result.setStatus(ResultStatus.NOLOGIN);
        result.setErrorMessage("用户未登录");
        return result;
    }
}
